package com.learn.gc;

import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Created by chenxin34 on 2018/6/28 下午3:13.
 */
public class ObjectSizeTest {
    public static void main(String[] args) {
        StringBuilder a = new StringBuilder();
        for (int i = 0; i <= 10000; i++){
            a.append("你");
        }
        System.out.println(ObjectSizeCalculator.getObjectSize(a.toString()));


        int x = 0;
        System.out.println(ObjectSizeCalculator.getObjectSize(x));
        System.out.println("size of Boolean Reference Type = " + ObjectSizeCalculator.getObjectSize(Boolean.FALSE));
        System.out.println("size of Integer Reference Type = " + ObjectSizeCalculator.getObjectSize(new Integer(1)));
        System.out.println("size of Double Reference Type = " + ObjectSizeCalculator.getObjectSize(Double.valueOf(1)));
        System.out.println("size of Character Reference Type = " + ObjectSizeCalculator.getObjectSize(Character.valueOf('a')));


        System.out.println("size of String Type = " + ObjectSizeCalculator.getObjectSize(""));
        System.out.println("size of String Type = " + ObjectSizeCalculator.getObjectSize("a"));
        System.out.println("size of String Type = " + ObjectSizeCalculator.getObjectSize("abc"));


        System.out.println("*******  array test *****");
        System.out.println(ObjectSizeCalculator.getObjectSize(new int[0]));
        System.out.println(ObjectSizeCalculator.getObjectSize(new int[1])); //8字节对齐
        System.out.println(ObjectSizeCalculator.getObjectSize(new int[2]));


        Map<String, Object> map = new HashMap<>();
        map.put("11", 11);
        map.put("22", "22");
        map.put("33", 33L);
        map.put("44", 44.44);
        System.out.println("Map: " + ObjectSizeCalculator.getObjectSize(map));
    }
}
